let rec power x n =
   if x<0 then invalid_arg "puisance negative"
   else if x = 0 then 0
   else match n with
     |0 -> 1
     |1 -> x  
     |n -> x*power x (n-1);;

let rec application l x = 
 match l with
  |[] -> 0
  |(y,n)::l -> y * power x n + application l x;;

let rec add  l1 l2 = match (l1,l2) with
  |([],l2) -> l2 |(l1,[]) -> l1
  |((a1,b1)::l1,(a2,b2)::l2) -> if b1=b2 then ((a1+a2),b1)::add  l1 l2
                                else if b1<b2 then (a1,b1)::add l1 ((a2,b2)::l2)
                                      else (a2,b2)::add ((a1,b1)::l1) l2;;

let rec soustract l1 l2 = match (l1,l2) with
  |([],l2) -> l2 |(l1,[]) -> l1
  |((a1,b1)::l1,(a2,b2)::l2) -> if b1=b2 then ((a1-b1),b1):: soustract l1 l2
                                else if b1<b2 then (a1,b1):: soustract l1 ((a2,b2)::l2)
                                      else (-a2,b2):: soustract ((a1,b1)::l1) l2;;

let rec deriv l = match l with
  |[] -> []
  |(e1,e2)::l -> if e2-1=0 then deriv l
                           else (e2*e1,e2-1)::deriv l;;

(*let rec mult l1 l2 = match l2 with
	|[] -> l1
	|(x,n)::l -> let rec f l1 = match l1 with
				|[] -> []
				|(y,m)::liste -> (x*y,n*m)::f liste
                *)
